<!-- 数据回写记录 -->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      ref="crud"
      v-model="form"
      :permission="permissionList"
      :before-open="beforeOpen"
      :page.sync="page"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot-scope="{ row }" slot="status">
        <span v-if="row.status == 0" class="stateWords-warning">待处理</span>
        <span v-if="row.status == 1" class="stateWords-success">成功</span>
        <span v-if="row.status == 2" class="stateWords-danger">失败</span>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { getList, getDetail } from '@/api/monitor/dataReplyMsg';
import { mapGetters } from 'vuex';

export default {
  data() {
    return {
      form: {},
      selectionList: [],
      query: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      option: {
        height: 'calc(100vh - 350px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        viewBtn: true,
        viewText: '详情',
        viewBtnText: '详情',
        editBtn: false,
        addBtn: false,
        delBtn: false,
        menuWidth: 100,
        labelWidth: 120,
        column: [
          {
            label: '回写名称',
            prop: 'name',
            search: true,
            overHidden: true
          },
          {
            label: '回写Tag',
            prop: 'tag',
            search: true
          },
          {
            label: '单据号',
            prop: 'sheetNo',
            search: true
          },
          {
            label: '单据类型',
            prop: 'sheetType',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=sheet_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            width: 80
          },
          {
            label: '请求参数',
            prop: 'requestParam',
            type: 'textarea',
            overHidden: true,
            span: 24,
            minRows: 3,
            maxRows: 5
          },
          {
            label: '回写结果',
            prop: 'result',
            type: 'textarea',
            overHidden: true,
            span: 24,
            minRows: 3,
            maxRows: 5
          },
          {
            label: '状态',
            prop: 'status',
            width: 80,
            html: true,
            span: 24,
            type: 'select',
            dicData: [
              {
                label: '待处理',
                value: 0
              },
              {
                label: '成功',
                value: 1
              },
              {
                label: '失败',
                value: 2
              }
            ]
          },
          {
            label: '创建时间',
            prop: 'createTime',
            width: 150,
            span: 24
          },
          {
            label: '更新时间',
            prop: 'updateTime',
            width: 150,
            span: 24
          }
        ]
      },
      data: []
    };
  },

  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.dataReplyMsg_view, false)
      };
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    beforeOpen(done, type) {
      if (['view'].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data || this.form;
        });
      }
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .dataReplyMsg-dialog {
  .el-dialog__body {
    padding-top: 0;
    .avue-crud__menu {
      display: none;
    }
  }
  .title {
    font-size: 16px;
  }
}
</style>
